package org.example.myleet.p746;

/**
 * DP, f[i] = min(f[i-1]+cost[i], f[i-2]+cost[i])
 * 1 ms
 */
public class Solution {
    public int minCostClimbingStairs(int[] cost) {
        int dp0 = cost[0];
        int dp1 = Math.min(dp0+cost[1], cost[1]);
        int dpi;
        for (int i=2;i<cost.length;i++) {
            dpi = Math.min(dp1 + cost[i], dp0 + cost[i]);
            dp0 = dp1;
            dp1 = dpi;
        }
        dpi = Math.min(dp1, dp0);
        return dpi;
    }

//    public int minCostClimbingStairs(int[] cost) {
//        int[] dp = new int[cost.length+1];
//        dp[0] = cost[0];
//        dp[1] = Math.min(dp[0]+cost[1], cost[1]);
//        for (int i=2;i<cost.length;i++) {
//            dp[i] = Math.min(dp[i-1] + cost[i], dp[i-2] + cost[i]);
//        }
//        dp[cost.length] = Math.min(dp[cost.length-1], dp[cost.length-2]);
//        return dp[cost.length];
//    }
}
